"""
发送post请求
"""
import requests


class YouDao:
    # 初始化
    def __init__(self, word):
        self.url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"
        self.header = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36"
        }
        # 要翻译的词
        self.word = word
        self.data = {
            'i': self.word,
            'from': 'AUTO',
            'to': 'AUTO',
            'smartresult': 'dict',
            'client': 'fanyideskweb',
            'salt': '16057682615040',
            'sign': '3756caa932d809afcea01819181986b0',
            'lts': '1605768261504',
            'bv': '02edb5d6c6ac428cd4393133e5aab14',
            'doctype': 'json',
            'version': '2.1',
            'keyfrom': 'fanyi.web',
            'action': 'FY_BY_REALTlME',
        }

    # 爬取数据的函数
    def get_data(self):
        result = requests.post(self.url, header=self.header, data=self.data)
        return result.content.decode()
